package 哈希.同构字符串205;

import java.util.HashMap;
import java.util.Map;

public class Solution {

    public static boolean isIsomorphic(String s, String t) {
        if(s.length() != t.length()){
            return false;
        }

        Map<Character,Character> maps = new HashMap<>();
        Map<Character,Character> mapt = new HashMap<>();

        for(int i=0;i<s.length();i++){
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            if(!maps.containsKey(sc)){
                maps.put(sc,tc);
            }else{
                if(maps.get(sc) != tc){
                    return false;
                }
            }

            if(!mapt.containsKey(tc)){
                mapt.put(tc,sc);
            }else{
                if(mapt.get(tc) != sc){
                    return false;
                }
            }
        }

        return true;
    }

    public static void main(String[] args) {
        String s = "title";
        String t = "paper";
        System.out.println(isIsomorphic(s,t));
    }


}
